<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\web\View;
use app\assets\AppAsset;

/* @var $this yii\web\View */
/* @var $searchModel app\models\PersoninfoSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '学生账号';
$this->params['breadcrumbs'][] = $this->title;

$js=<<< Js
var exportLink = document.getElementById('export');
	exportLink.addEventListener('click', function(e){
		e.preventDefault();
		if(e.target.nodeName === "A"){
			tableExport('table-export', '导出文件', e.target.getAttribute('data-type'));
		}	

	}, false);
Js;
$this->registerJs($js, View::POS_END, 'myAjax');       
?>
<script src="<?= \Yii::getAlias('@web')?>/js/Blob.js"></script>

<script src="<?= \Yii::getAlias('@web')?>/js/FileSaver.js"></script>

<script src="<?= \Yii::getAlias('@web')?>/js/tableExport.js"></script>
<div class="personinfo-index">

    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <div>
        <div style="float: left;margin-right: 5px;" >
            <?= Html::a('添加', ['personinfo/create'], ['class' => 'btn btn-success']) ?>
        </div>
    </div>
    <div id="import"><a class="btn btn-info"  data-type="xls" href="<?=Yii::getAlias('@web'.'/personinfo/import')?>">导入excel</a></div>
    <div class="table-responsive">
    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'tableOptions'=>[
            'id'=>'table-export',
            'class' => 'table table-striped table-bordered',
            ],
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],
        	'stu_id',
            'stu_name',
            
        		'sex'=>[
        				'value'=>function ($model){
        				return ($model->sex==0)?'男':'女';
        				},
        				'attribute'=>'sex',
        				'filter'=>['0'=>'男','1'=>'女'],
        				 
        				],
            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>
    </div>
</div>
